﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HKB.Common;
using HKB.Web;
using HKB.Web.Shop.Member;
using System.Data;

public partial class Member_Shop_News : Member
{
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			this.labPage.Text = "1";
			this.GridViewDataBound();
		}
	}

	protected void GridViewDataBound()
	{
		string strUserID = base.user.UserID.ToString();
		string strShopID = base.user.ShopID.ToString();
		string text = "SELECT [newsID],[newsType],[newsTitle],[newsContext],[newsSource],[Createtime],[Updatetime],[ShopId],[UserId] FROM [DB_HKB].[dbo].[HLShop_News] WHERE SHOPID='"+ strShopID +"' AND USERID='" + strUserID + "' ";
		if (this.ddlType.SelectedValue != "0")
			text += " AND newsType = '" + ddlType.SelectedItem.Text + "'";
		text += " ORDER BY UPDATETIME DESC";
		//获取数据源
		PagedDataSource pds = new PagedDataSource();
		DataTable dataTable = this.conn.GetDataTable(text);
		pds.DataSource = dataTable.DefaultView;
		//设置允许分页
		pds.AllowPaging = true;
		//设置在单页上显示的条数
		pds.PageSize = 20;
		//获取或设置当前页的索引
		pds.CurrentPageIndex = Int32.Parse(labPage.Text) - 1;

		//设置页的总数
		LabCountPage.Text = pds.PageCount.ToString();
		//设置按钮的可操作性
		lbtnDownPage.Enabled = true;
		lbtnFirstPage.Enabled = true;
		lbtnNextPage.Enabled = true;
		lbtnpritPage.Enabled = true;
		if (pds.CurrentPageIndex < 1)
		{
			lbtnFirstPage.Enabled = false;
			lbtnpritPage.Enabled = false;
		}
		if (pds.CurrentPageIndex == pds.PageCount - 1)
		{
			lbtnDownPage.Enabled = false;
			lbtnNextPage.Enabled = false;
		}
		this.Repeater1.DataSourceID = "";
		this.Repeater1.DataSource = pds;
		this.Repeater1.DataBind();
	}

	//设置首页按钮功能
	protected void lbtnFirstPage_Click(object sender, EventArgs e)
	{
		labPage.Text = "1";
		this.GridViewDataBound();
	}
	//设置上一页按钮功能
	protected void lbtnpritPage_Click(object sender, EventArgs e)
	{
		labPage.Text = (Int32.Parse(labPage.Text) - 1).ToString();
		this.GridViewDataBound();
	}
	//设置下一页按钮功能
	protected void lbtnNextPage_Click(object sender, EventArgs e)
	{
		labPage.Text = (Int32.Parse(labPage.Text) + 1).ToString();
		this.GridViewDataBound();
	}
	//设置尾页按钮功能
	protected void lbtnDownPage_Click(object sender, EventArgs e)
	{
		labPage.Text = LabCountPage.Text;
		this.GridViewDataBound();
	}

	protected void Repeater1_ItemDataBound(object source, RepeaterCommandEventArgs e)
	{
 
	}

	protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
	{
		this.GridViewDataBound();
	}

	protected void Button_Command(object sender, CommandEventArgs e)
	{
		string text = Text.CheckNumList(Fetch.GetOrPost("New_Select"));
		Shop_Product shop_Product = new Shop_Product(this.conn);
		if (text != "")
		{
			string text2 = text;
			string[] array = text2.Split(new char[]
			{
				','
			});
			for (int i = 0; i < array.Length; i++)
			{
				if (e.CommandName.ToString() == "deleteNews")
				{
					int num = this.conn.Execute("delete [HLShop_News] where newsID =" + int.Parse(array[i]));
				}
			}
			int num2 = shop_Product.EditSaleProductProtity(text2, e.CommandName.ToString());
			this.GridViewDataBound();
		}
	}
}